home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_03 / 8n03074a < prev    next >
Text File  |  1990-03-18  |  1KB  |  52 lines

  1. *****Listing 2*****
  2.  
  3. --------------------------------------------------------------
  4.        /*
  5.        *
  6.        *   This is the function that implements Demptser's rule
  7.        *   of combination.
  8.        *   vector1 & vector2 are belief vectors.  vector2 will hold 
  9.        *   the result of the combination.
  10.        *
  11.        */
  12.  
  13. combine_using_dempsters_rule(vector1, vector2)
  14.    float vector1[LENGTH_OF_BELIEF_VECTOR],
  15.          vector2[LENGTH_OF_BELIEF_VECTOR];
  16. {
  17. float denominator,  sum_vector[LENGTH_OF_BELIEF_VECTOR];
  18.  
  19. int   a,  i,  place;
  20.  
  21. /* set the sums to zero */
  22. for(i=0; i<LENGTH_OF_BELIEF_VECTOR; i++)
  23.    sum_vector[i] = 0.0;
  24.  
  25. /* Now go through the intersection tableau.      
  26. *  Look for the intersection of non-zero beliefs 
  27. *  and save their products.                      */
  28.  
  29. for(a=1; a<LENGTH_OF_BELIEF_VECTOR; a++){
  30.  
  31.    if(vector2[a] > 0.0){
  32.  
  33.       for(i=0; i<LENGTH_OF_BELIEF_VECTOR; i++){
  34.          place = i & a;
  35.          if(vector1[i] > 0.0)
  36.           sum_vector[place] = (vector1[i] * vector2[a]) + sum_vector[place];
  37.       }  /* ends loop over i */
  38.  
  39.    }  /* ends if vector2[a] > 0.0 */
  40.  
  41. }  /* ends loop over a */
  42.  
  43. denominator = 1.0 - sum_vector[0];
  44. for(i=1; i<LENGTH_OF_BELIEF_VECTOR; i++)
  45.    vector1[i] = sum_vector[i]/denominator;
  46.  
  47. }  /* ends combine_using_dempsters_rule */
  48.  
  49. Figure 8 - C Code to Implement Dempster's Rule of Combination
  50. ----------------------------------------------------------------
  51.  
  52.